package com.zsy.petshop_01.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {

    private Integer code;
    private Boolean success;
    private String message;
    private T data;

    public static final Integer success_code = 200;
    public static final Integer fail_code = 500;

    public static <T> ResponseResult<?> success(String message, T data){
        return new ResponseResult<>(success_code,true,message,data);
    }

    public static <T> ResponseResult<?> success(String message){
        return new ResponseResult<>(success_code,true, message,null);
    }

    public static <T> ResponseResult<?> success(T data){
        return new ResponseResult<>(success_code,true,null,data);
    }

    public static <T> ResponseResult<?> success(){
        return new ResponseResult<>(success_code,true,null,"OK");
    }


    public static <T> ResponseResult<?> fail(RuntimeException e){
        return new ResponseResult<>(fail_code,false,e.getMessage(),null);
    }

    public static <T> ResponseResult<?> fail(String message){
        return new ResponseResult<>(fail_code,false,message,null);
    }

}
